package bytes

import (
	"bytes"
	"fmt"
	"strings"
)

func Join() {
	b := [][]byte{[]byte("你好"), []byte("世界")}
	s1 := []byte(",")
	fmt.Println(string(bytes.Join(b, s1)))
	s1 = []byte("#")
	fmt.Println(string(bytes.Join(b, s1)))

}

func Runes() {
	b := []byte("你好世界")
	r := bytes.Runes(b)
	fmt.Println("转换前的字符串长度：", len(b))
	fmt.Println("转换后的字符串长度：", len(r))
}

func Replace() {
	b := []byte("hello world")
	old := []byte("o")
	new := []byte("ee")
	// 替换0个old字符
	fmt.Println(string(bytes.Replace(b, old, new, 0)))
	// 替换1个old字符
	fmt.Println(string(bytes.Replace(b, old, new, 1)))
	// 替换2个old字符
	fmt.Println(string(bytes.Replace(b, old, new, 2)))
	// 替换所有old字符
	fmt.Println(string(bytes.Replace(b, old, new, -1)))
}

func Repeat() {
	b := []byte("hi")
	fmt.Println(string(bytes.Repeat(b, 1)))
	fmt.Println(string(bytes.Repeat(b, 2)))
	fmt.Println(string(bytes.Repeat(b, 3)))
}

func Count() {
	b := []byte("helloooooo")
	s1 := []byte("h")
	s2 := []byte("l")
	s3 := []byte("o")
	fmt.Println(bytes.Count(b, s1))
	fmt.Println(bytes.Count(b, s2))
	fmt.Println(bytes.Count(b, s3))
}

func Contains() {

	b := []byte("baidu.com")
	b2 := []byte("baidu")
	b3 := []byte("Baidu")

	fmt.Println(bytes.Contains(b, b2))
	fmt.Println(bytes.Contains(b, b3))

	fmt.Println(strings.Contains("hello go", "go"))

}

func TrnsType() {
	var i int = 100
	var b byte = 10
	// int <-> byte
	b = byte(i)
	i = int(b)

	var s string = "hello world"
	b2 := []byte{1, 2, 3}

	b2 = []byte(s)
	s = string(b2)
}
